package com.py.credit.service.impl;

import com.py.credit.dao.RuleBindingDao;
import com.py.credit.dao.XypjUserReportDao;
import com.py.credit.service.XypjUserReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Company: WWW.xypy.com.cn
 * @ClassName xypjUserReportServiceImpl
 * @Description: 信用评价查询业务实现
 * @Params: Test
 * @Author: YaoS
 * @Create: 2018-10-24 17:10
 **/
@Service
public class XypjUserReportServiceImpl implements XypjUserReportService {
    @Autowired
    XypjUserReportDao xypjUserReportDao;
    @Autowired
    RuleBindingDao ruleBindingDao;

    @Override
    public List<Map<String, Object>> selectLeftTable(String tableList,String tybm) {
        int editionId = ruleBindingDao.selectCurrentContentVersion();
        List<String> list = Arrays.asList(tableList.split(","));
        tableList=tableList.substring(0,tableList.length()-1);
        List<Map<String, Object>> table = xypjUserReportDao.getTableByList(list, editionId, tableList);

        for (Map map:table
             ) {
            map.put("totalCount",xypjUserReportDao.selectTableCount((String) map.get("resourceId"),tybm));
        }

        return table;
    }

    @Override
    public List<Map<String, Object>> selectColumns(String tableId) {
        List<Map<String, Object>> table = xypjUserReportDao.getCloumnByList(tableId);
        return table;
    }

	@Override
	public List<Map> getTableValuesByTybmAndTable(String tableName, String tybm) {
		// TODO Auto-generated method stub
		return xypjUserReportDao.getTableValuesByTybmAndTable(tableName, tybm);
	}



    @Override
    public String selectTybm(String ztmc, String bm, String type) {
        if(type.equals("C")){
            return xypjUserReportDao.selectFrTybm(ztmc);
        }else{
            return xypjUserReportDao.selectZrrTybm(ztmc, bm);
        }
    }

}
